<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>


    <style>
        .el-table .warning-row {
            background: oldlace;
        }

        .el-table .success-row {
            background: #f0f9eb;
        }
    </style>
</head>
<body>
<div id="app">


    <el-menu
            :default-active="activeIndex2"
            class="el-menu-demo"
            mode="horizontal"
            @select="handleSelect"
            background-color="#545c64"
            text-color="#fff"
            active-text-color="#ffd04b">
        <el-menu-item index="1"><a href="http://localhost:8080/vue-demo/showAllGoods.html">所有商品</a></el-menu-item>
        <el-submenu index="2">
            <template slot="title">我的工作台</template>
            <el-menu-item index="2-1"><a href="http://localhost:8080/vue-demo/usersMai.html" >修改个人信息</a></el-menu-item>
            <el-menu-item index="2-2"><a href="http://localhost:8080/vue-demo/showUserGoods.html" >管理商品</a></el-menu-item>
            <el-menu-item index="2-3">与客户聊天</el-menu-item>
            <el-menu-item index="2-4"><a href="http://localhost:8080/vue-demo/showCancelOrder.html" >我的商品售后</a></el-menu-item>
            <el-menu-item index="2-5"><a href="https://www.ele.me">管理收到的订单</a></el-menu-item>

        </el-submenu>
        <el-menu-item index="3" ><a href="http://localhost:8080/vue-demo/manageAddress.html" target="_blank">管理地址</a></el-menu-item>
        <el-menu-item index="4"><a href="http://localhost:8080/vue-demo/showMyGouwucar.html" target="_blank">我的购物车</a></el-menu-item>
        <el-menu-item index="5"><a href="http://localhost:8080/vue-demo/addPrice.html" target="_blank">积分充值</a></el-menu-item>
        <el-submenu index="6">
            <template slot="title">支付订单管理</template>
            <el-menu-item index="6-1"><a href="http://localhost:8080/vue-demo/showAllOrderForm.html" >所有订单</a></el-menu-item>
            <el-menu-item index="6-2"><a href="http://localhost:8080/vue-demo/showFalseOrderForm.html" >未付款订单</a></el-menu-item>
            <el-menu-item index="6-3"><a href="http://localhost:8080/vue-demo/showSuccessOrderForm.html" >已支付订单</a></el-menu-item>
        </el-submenu>
        <el-menu-item index="7" @click="signIn">每日签到</el-menu-item>
        <el-menu-item index="8" @click="dialogVisible11 = true">退出登录</el-menu-item>
    </el-menu>
    <!--添加数据的对话框表单-->
    <el-dialog
            title="退出登录"
            :visible.sync="dialogVisible11"
            width="30%">

        <el-form status-icon :rules="rules" ref="form" :model="goods_type" label-width="80px">
            <el-form-item>
                <el-button type="primary" @click="cancelLogin">确认要退出登录吗</el-button>
                <el-button @click="dialogVisible11 = false">取消</el-button>
            </el-form-item>
        </el-form>
    </el-dialog>

    <el-form :inline="true" :model="goods2" class="demo-form-inline">
        <el-form-item label="商品名称">
            <el-input v-model="goods2.goodsName" placeholder="商品名称"></el-input>
        </el-form-item>
        <el-form-item label="商品类型" prop="goodsType">
            <el-input  v-model="goods2.goodsType" readonly></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="dialogVisible4 = true">选择商品类型</el-button>
        </el-form-item>
        <!--<el-form-item label="分类">
            <el-select v-model="goods2.goodsType" placeholder="分类">
                <el-option label="默认" value="默认"></el-option>
                <el-option label="服饰" value="服饰"></el-option>
                <el-option label="首饰" value="首饰"></el-option>
                <el-option label="数码" value="数码"></el-option>
                <el-option label="文具" value="文具"></el-option>
            </el-select>
        </el-form-item>-->
        <el-form-item label="店铺">
            <el-input v-model="goods2.shopName" placeholder="店铺"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="onSubmit">查询</el-button>
        </el-form-item>
    </el-form>
    <!--添加数据的对话框表单-->
    <el-dialog
            title="选择商品类型"
            :visible.sync="dialogVisible4"
            width="30%">

        <el-form status-icon :rules="rules" ref="form" :model="goods2" label-width="80px" >
            <template >
                <el-table
                        :data="goods_type"
                        style="width: 100%"

                        :row-class-name="tableRowClassName">
                    <el-table-column
                            type="index"
                            width="50">
                    </el-table-column>
                    <el-table-column
                            prop="type"
                            label="商品种类"
                            align="center">
                    </el-table-column>
                    <el-table-column
                            align="center"
                            label="选择">
                        <template slot-scope="scope">
                            <!-- 在这里，你可以使用scope.$index来获取当前行的索引值 -->
                            <el-button type="primary" @click="selectType(scope.$index)">选择</el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </template>
            <!--<el-form-item label="商品类型">
                <el-select v-model="goods.goodsType" placeholder="请选择商品类型">
                    <el-option label="默认" value="默认"></el-option>
                    <el-option label="服饰" value="服饰"></el-option>
                    <el-option label="首饰" value="首饰"></el-option>
                    <el-option label="数码" value="数码"></el-option>
                    <el-option label="文具" value="文具"></el-option>
                </el-select>
            </el-form-item>-->
            <el-form-item label="商品类型" prop="goodsType">
                <el-input  v-model="goods2.goodsType" readonly></el-input>
            </el-form-item>
            <el-form-item>
                <el-button @click="dialogVisible4 = false">确定</el-button>
            </el-form-item>
        </el-form>

    </el-dialog>
    <!--添加数据的对话框表单-->
    <el-dialog
            title="添加到购物车"
            :visible.sync="dialogVisible"
            width="30%">
        <el-form status-icon :rules="rules" ref="form" :model="gouwucar" label-width="80px" >
            <el-form-item label="收货地址" prop="userAddress">
                <el-input v-model="gouwucar.userAddress" readonly></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="dialogVisibleTwo = true">更改收货地址</el-button>
            </el-form-item>
        </el-form>
        <el-form status-icon :rules="rules" ref="form" :model="gouwucar" label-width="80px" >
            <el-form-item label="商品名称" prop="goodsName">
                <el-input v-model="gouwucar.goodsName" readonly></el-input>
            </el-form-item>
            <el-form-item label="数量" prop="goodsNum">
                <el-input v-model.number="gouwucar.goodsNum" placeholder="请输入数量"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="addgoods">添加到购物车</el-button>
                <el-button @click="dialogVisible = false">取消</el-button>
            </el-form-item>
        </el-form>

    </el-dialog>
    <!--新增地址的对话框表单-->
    <el-dialog
            title="新增地址"
            :visible.sync="dialogVisible1"
            width="30%">
        <el-form status-icon :rules="rules" ref="form" :model="address" label-width="80px" >
            <el-form-item label="地址" prop="userAddress">
                <el-input v-model="address.userAddress" placeholder="请输入地址" :maxlength="12"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="addAddress">立即创建</el-button>
                <el-button @click="dialogVisible1 = false">取消</el-button>
            </el-form-item>
        </el-form>

    </el-dialog>
    <!--修改地址的对话框表单-->
    <el-dialog
            title="修改地址"
            :visible.sync="dialogVisibleFour1"
            width="30%">
        <el-form status-icon :rules="rules" ref="form" :model="address" label-width="80px" >
            <el-form-item label="地址" prop="userAddress">
                <el-input v-model="address.userAddress" placeholder="请输入地址" :maxlength="12"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="modifyAddress2(address.addressID)">立即修改</el-button>
                <el-button @click="dialogVisibleFour1 = false">取消</el-button>
            </el-form-item>
        </el-form>

    </el-dialog>
    <!--删除地址的对话框表单-->
    <el-dialog
            title="删除地址"
            :visible.sync="dialogVisibleThree1"
            width="30%">

        <el-form status-icon :rules="rules" ref="form" :model="address" label-width="80px" >
            <el-form-item>
                <el-button type="primary" @click="deleteAddress2(address.addressID)">确认删除</el-button>
                <el-button @click="dialogVisibleThree1 = false">取消</el-button>
            </el-form-item>
        </el-form>
    </el-dialog>
    <!--管理地址的对话框表单-->
    <el-dialog
            title="管理地址"
            :visible.sync="dialogVisibleTwo"
            width="60%">

        <el-button type="danger" @click="dialogVisible1 = true">新增</el-button>
        <el-tag>默认地址</el-tag>
        <el-input v-model="morenAddress.userAddress" readonly>默认地址</el-input>
        <!--表格-->
        <template>
            <el-table
                    :data="AddressTableData"
                    style="width: 100%"

                    :row-class-name="tableRowClassName">
                <el-table-column
                        type="index"
                        width="50">
                </el-table-column>
                <el-table-column
                        prop="userAddress"
                        label="我的地址"
                        align="center">
                </el-table-column>
                <el-table-column
                        align="center"
                        label="操作">
                    <template slot-scope="scope">
                        <!-- 在这里，你可以使用scope.$index来获取当前行的索引值 -->
                        <el-button type="primary" @click="updateAddress(scope.$index)">设置为本次的收货地址</el-button>
                        <el-button type="primary" @click="modifyMorenAddress(scope.$index)">设置为默认地址</el-button>
                        <el-button type="primary" @click="modifyAddress(scope.$index)">修改</el-button>
                        <el-button type="danger" @click="deleteAddress(scope.$index)">删除</el-button>
                    </template>
                </el-table-column>

            </el-table>
        </template>
    </el-dialog>
    <!--查询详细数据的对话框表单-->
    <el-dialog
            title="查询详细数据"
            :visible.sync="dialogVisible2"
            width="30%">
        <el-form status-icon :rules="rules" ref="form" :model="goods" label-width="80px" >
            <div class="demo-image">
                <div class="block" v-for="fit in fits" :key="fit">
                    <span class="demonstration">{{ fit }}</span>
                    <el-image
                            style="width: 100px; height: 100px"
                            :src="goods.url"
                            :fit="fit"></el-image>
                </div>
            </div>
            <el-form-item label="好评数" prop="goodsGreat">
                <el-input v-model="goods.goodsGreat" readonly></el-input>
            </el-form-item>
            <el-form-item label="浏览量" prop="lookNum">
                <el-input v-model="goods.lookNum" readonly></el-input>
            </el-form-item>
            <el-form-item label="小店名称" prop="shopName">
                <el-input v-model="goods.shopName" readonly></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="lookComments">查看评论</el-button>
            </el-form-item>
        </el-form>
    </el-dialog>
    <!--查询详细数据的对话框表单-->
    <el-dialog
            title="查询详细数据"
            :visible.sync="dialogVisible3"
            width="30%">
        <template>
            <el-table
                    :data="goodsComment"
                    style="width: 100%"
                    @selection-change="handleSelectionChange"
                    :row-class-name="tableRowClassName">
                <el-table-column
                        type="index"
                        width="50">
                </el-table-column>
                <el-table-column
                        prop="date"
                        label="发布评论时间"
                        align="center">
                </el-table-column>
                <el-table-column
                        prop="goodsComment"
                        label="评论"
                        align="center">
                </el-table-column>
            </el-table>
        </template>

    </el-dialog>
    <!--表格-->
    <template>
        <el-table
                :data="tableData"
                style="width: 100%"
                @selection-change="handleSelectionChange"
                :row-class-name="tableRowClassName"
                :default-sort = "{prop: 'date', order: 'descending'}">
            <el-table-column
                    type="index"
                    width="50">
            </el-table-column>
            <el-table-column
                    prop="date"
                    label="商品上架日期"
                    sortable
                    align="center">
            </el-table-column>
            <el-table-column
                    prop="goodsXiaoLiang"
                    label="销量"
                    sortable
                    align="center">
            </el-table-column>
            <el-table-column
                    prop="goodsGreat"
                    label="好评数"
                    sortable
                    align="center">
            </el-table-column>
            <el-table-column
                    prop="goodsName"
                    align="center"
                    label="商品名称">
            </el-table-column>
            <el-table-column
                    prop="goodsMessage"
                    align="center"
                    label="商品信息">
            </el-table-column>
            <el-table-column
                    prop="goodsType"
                    align="center"
                    label="商品种类">
            </el-table-column>
            <el-table-column
                    prop="price"
                    align="center"
                    label="商品价格">
            </el-table-column>
            <el-table-column
                    align="center"
                    label="操作">

                <template slot-scope="scope">
                    <!-- 在这里，你可以使用scope.$index来获取当前行的索引值 -->
                    <el-button type="primary" @click="selectGoodsMessage(scope.row)">查询商品详细信息</el-button>
                    <el-button type="danger" @click="addGoods2(scope.row)">添加到购物车</el-button>
                </template>
            </el-table-column>
        </el-table>
    </template>
    <!--分页工具条-->
    <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-sizes="[5, 10, 20, 40]"
            :page-size="5"
            layout="total, sizes, prev, pager, next, jumper"
            :total="totalCount">
    </el-pagination>
</div>


<script src="js/vue.js"></script>
<script src="element-ui/lib/index.js"></script>
<link rel="stylesheet" href="element-ui/lib/theme-chalk/index.css">
<script src="js/axios-0.18.0.js"></script>

<script>
    new Vue({
        el:"#app",

        mounted(){
            //当页面加载完成之后，发布异步请求获取数据

            var _this = this;
            axios({
                method:"get",
                url:"http://localhost:8080/vue-demo/selectByPage?currentPage="+_this.currentPage+"&pageSize="+_this.pageSize
            }).then(function (resp) {
                _this.tableData = resp.data.rows;
                _this.totalCount = resp.data.totalCount;
            })

            axios({
                method:"get",
                url:"http://localhost:8080/vue-demo/modifyAddress"
            }).then(function (resp) {
                _this.AddressTableData = resp.data;
            })

            axios({
                method:"get",
                url:"http://localhost:8080/vue-demo/modifyAddress2"
            }).then(function (resp) {
                _this.morenAddress = resp.data;
                _this.gouwucar.userAddress = resp.data.userAddress;
            })
            axios({
                method:"get",
                url:"http://localhost:8080/vue-demo/showAllGoodsType"
            }).then(function (resp) {
                _this.goods_type = resp.data;
            })
        },
        methods: {

            handleSelect(key, keyPath) {
                console.log(key, keyPath);
            },
            tableRowClassName({row, rowIndex}) {
                if (rowIndex === 1) {
                    return 'warning-row';
                } else if (rowIndex === 3) {
                    return 'success-row';
                }
                return '';
            },//复选框选中后执行的方法
            handleSelectionChange(val) {
                this.multipleSelection = val;

                console.log(this.multipleSelection);
            },
            selectType(index) {
                //console.log(index);
                //console.log(this.goods_type[index]);
                this.goods2.goodsType = this.goods_type[index].type;
            },
            onSubmit() {
                //console.log(this.goods2);
                var _this = this;
                //发送请求
                axios({
                    method : "post",
                    url:"http://localhost:8080/vue-demo/onSubmit?currentPage="+_this.currentPage+"&pageSize="+_this.pageSize,
                    data:_this.goods2
                }).then(function (resp) {
                    _this.tableData = resp.data.rows;
                    _this.totalCount = resp.data.totalCount;
                })
            },
            //分页
            handleSizeChange(val) {
               // console.log(`每页 ${val} 条`);
                this.pageSize = val;
                this.selectAll();
            },
            handleCurrentChange(val) {
                //console.log(`当前页: ${val}`);
                this.currentPage = val;
                this.selectAll();
            },
            selectAll(){
                var _this = this;
                axios({
                    method:"get",
                    url:"http://localhost:8080/vue-demo/selectByPage?currentPage="+_this.currentPage+"&pageSize="+_this.pageSize
                }).then(function (resp) {
                    _this.tableData = resp.data.rows;
                    _this.totalCount = resp.data.totalCount;
                })
            },
            modifyAddress2(addressID) {
                //console.log(addressID);
                var _this = this;
                //发送请求
                axios({
                    method : "post",
                    url:"http://localhost:8080/vue-demo/modifyAddress3",
                    data:_this.address
                }).then(function (resp) {

                    if (resp.data === "success") {
                        alert("修改地址成功")
                        _this.dialogVisibleFour1 =  false
                    }
                })
            },
            modifyAddress(index) {
                //console.log(index);
                //console.log(this.tableData[index].goodsID);
                this.address.addressID = this.AddressTableData[index].addressID;
                this.address.userAddress = this.AddressTableData[index].userAddress;
                this.dialogVisibleFour1=  true;
            },
            modifyMorenAddress(index) {
                //console.log(index);
                //console.log(this.tableData[index].goodsID);
                this.address.addressID = this.AddressTableData[index].addressID;
                this.address.userAddress = this.AddressTableData[index].userAddress;
                var _this = this;
                //发送请求
                axios({
                    method : "post",
                    url:"http://localhost:8080/vue-demo/modifyAddress4",
                    data:_this.address
                }).then(function (resp) {

                    if (resp.data === "success") {
                        alert("设置默认地址成功")
                    }
                })
            },
            updateAddress(index) {
                //console.log(index);
                //console.log(this.tableData[index].goodsID);
                //this.ReceiveAddress.userAddress = this.AddressTableData[index].userAddress;
                this.gouwucar.userAddress = this.AddressTableData[index].userAddress;
            },
            addAddress() {
                //console.log(this.AddressTableData);
                var _this = this;
                //发送请求
                axios({
                    method : "post",
                    url:"http://localhost:8080/vue-demo/addAddress",
                    data:_this.address
                }).then(function (resp) {

                    if (resp.data === "success") {
                        alert("新增地址成功")
                        _this.dialogVisible1 =  false
                    }
                })
            },
            deleteAddress2(addressID) {
                //console.log(addressID);
                var _this = this;
                //发送请求
                axios({
                    method : "post",
                    url:"http://localhost:8080/vue-demo/deleteAddress",
                    data:addressID
                }).then(function (resp) {

                    if (resp.data === "success") {
                        alert("删除地址成功")
                        _this.dialogVisibleThree1 =  false
                    }
                })
            },
            deleteAddress(index) {
                //console.log(index);
                //console.log(this.AddressTableData[index].addressID);
                this.address.addressID = this.AddressTableData[index].addressID;
                this.address.userAddress = this.AddressTableData[index].userAddress;
                this.dialogVisibleThree1 =  true;
            },
            addGoods2(goods) {
                //console.log(index);
                //console.log(this.goods2);
                //console.log(goods);
                this.gouwucar.goodsID = goods.goodsID;
                this.gouwucar.goodsName = goods.goodsName;
                this.gouwucar.goodsMessage = goods.goodsMessage;
                this.gouwucar.price = goods.price;
                // console.log(this.gouwucar);
                this.dialogVisible =  true;

            },
            selectGoodsMessage(goods) {
                //console.log(index);
                //console.log(this.tableData[index]);
                this.goods = goods;
                var _this = this;
                //发送请求
                axios({
                    method : "post",
                    url:"http://localhost:8080/vue-demo/selectGoodsMessage",
                    data:_this.goods
                }).then(function (resp) {
                    _this.dialogVisible2 =  true;
                })


            },
            signIn(){
                //this.goods = this.tableData[index];
                var _this = this;
                //发送请求
                axios({
                    method : "post",
                    url:"http://localhost:8080/vue-demo/signIn",
                }).then(function (resp) {
                    if (resp.data === "success") {
                        alert("今日签到成功，已为您增加2积分")
                    }
                    else if(resp.data === "error"){
                        alert("今日已签到")
                    }
                })
            },
            lookComments(){
                //this.goods = this.tableData[index];
                var _this = this;
                //发送请求
                axios({
                    method : "post",
                    url:"http://localhost:8080/vue-demo/lookComments",
                    data:_this.goods
                }).then(function (resp) {
                    _this.goodsComment = resp.data;
                    _this.dialogVisible3 =  true;
                })
            },
            cancelLogin(){
                //this.goods = this.tableData[index];
                var _this = this;
                //发送请求
                axios({
                    method : "post",
                    url:"http://localhost:8080/vue-demo/cancelLogin",
                }).then(function (resp) {
                    if (resp.data === "success") {
                        alert("您已经退出登录")
                        window.location.href = "http://localhost:8080/vue-demo/hello.html";
                    }
                })
            },
            addgoods() {
                var _this = this;
                //发送请求
                axios({
                    method : "post",
                    url:"http://localhost:8080/vue-demo/addToGouwucar",
                    data:_this.gouwucar
                }).then(function (resp) {

                    if (resp.data === "success") {
                        alert("添加购物车成功")
                        _this.dialogVisible =  false
                    }
                })
            },
        },
        data() {

            var checkNum = (rule, value, callback) => {
                if (value <= 0) {
                    return callback(new Error('最少买一件'));
                }
                else {
                    if(value > 5){
                        callback(new Error('一次最多买5件'));
                    }
                    if (!Number.isInteger(value)) {
                        callback(new Error('必须是整数'));
                    }
                    else {
                        callback();
                    }
                }
            }
            var validateAddress = (rule, value, callback) => {
                if (value === '') {
                    return callback(new Error('请输入地址'));
                } else {
                    if(/\s/.test(value)){
                        //如果存在空格
                        return callback(new Error('地址不可以有空格'));
                    }
                    else {
                        callback();
                    }
                    //callback();
                }
            }
            return {
                fits: [''],
                //每页5条
                pageSize:5,
                totalCount:100,
                activeIndex: '1',
                activeIndex2: '1',
                currentPage: 1,
                //搜索表单数据
                gouwucar: {
                    goodsName: '',
                    goodsMessage:'',
                    goodsNum:'1',
                    goodsID:'',
                    userID:'',
                    price: '',
                    userAddress:'',
                },
                tableData: [{
                    goodsName: '',
                    goodsType: '默认',
                    goodsDianPu: '',
                    date: '',
                    goodsMessage: '',
                    goodsGreat: '',
                    goodsXiaoLiang: '',
                    goodsNum:'',
                    statue:'',
                    id:'',
                    goodsID:'',
                    price: '',
                    shopName:'',
                    lookNum:'',
                    url:'',
                }],
                goodsComment: [{
                    userID:'',
                    goodsID:'',
                    goodsComment:'',
                    commentTime:'',
                    date:''
                }],
                goods: {
                    goodsName: '',
                    goodsType: '默认',
                    goodsDianPu: '',
                    date: '',
                    goodsMessage: '',
                    goodsGreat: '',
                    goodsXiaoLiang: '',
                    goodsNum:'',
                    statue:'',
                    id:'',
                    goodsID:'',
                    price: '',
                    shopName:'',
                    lookNum:'',
                    url:'',
                },
                goods2: {
                    goodsName: '',
                    goodsType: '默认',
                    goodsDianPu: '',
                    date: '',
                    goodsMessage: '',
                    goodsGreat: '',
                    goodsXiaoLiang: '',
                    goodsNum:'',
                    statue:'',
                    id:'',
                    goodsID:'',
                    price: '',
                    shopName:'',
                    lookNum:'',
                    url:'',
                },
                AddressTableData: [{
                    userAddress: '',
                    userID: '',
                    addressID: '',
                }],
                morenAddress:{
                    userAddress: '',
                    userID: '',
                    addressID: ''
                },
                address: {
                    userAddress: '',
                    userID: '',
                    addressID: ''
                },
                goods_type: [{
                    type:'',
                    goods_id:''
                }],
                rules: {
                    goodsNum: [
                        {validator: checkNum, trigger: 'blur'}
                    ],
                    userAddress:[
                        {validator:validateAddress, trigger: 'blur' }
                    ],
                },
                //展开对话框
                dialogVisible1: false,
                dialogVisible2: false,
                dialogVisible3: false,
                dialogVisible4: false,
                dialogVisible: false,
                dialogVisibleTwo: false,
                dialogVisibleThree1: false,
                dialogVisibleFour1: false,
                dialogVisible10: false,
                dialogVisible11: false,
            }
        }
    })
</script>

</body>
</html>